﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace WindowsPhoneApplication1
{
    public partial class searchPage : PhoneApplicationPage
    {

        String area,diff;

        public searchPage()
        {
            InitializeComponent();
        }

        private void enterArea_GotFocus(object sender, RoutedEventArgs e)
        {
            if (enterArea.Text == "Enter Area")
                enterArea.Text = "";
                
        }

        private void enterArea_LostFocus(object sender, RoutedEventArgs e)
        {
            if (enterArea.Text == String.Empty)
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Black;
                enterArea.Foreground = Brush2;
                enterArea.Text = "Enter Area";
            }
            
            else
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Blue;
                enterArea.Foreground = Brush2;
                area = enterArea.Text;
            }
        }

        private void difficulty_GotFocus(object sender, RoutedEventArgs e)
        {
            if (difficulty.Text == "Enter Difficulty")
                difficulty.Text = "";
        }

        private void difficulty_LostFocus(object sender, RoutedEventArgs e)
        {
            if (difficulty.Text == String.Empty)
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Black;
                difficulty.Foreground = Brush2;
                difficulty.Text = "Enter Difficulty";
            }
            
            else
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Blue;
                difficulty.Foreground = Brush2;
                diff = difficulty.Text;
            }
        }

        private void search_Click(object sender, RoutedEventArgs e)
        {
            //TODO: searchInDB(area, diff)
        }

        private void recommended_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/recommendedPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void searchByLoc_Click(object sender, RoutedEventArgs e)
        {
            IsolatedStorageSettings trkData = IsolatedStorageSettings.ApplicationSettings;

            if (!trkData.Contains("sourcePg"))
                trkData.Add("sourcePg", "srcByLoc");
            else
                trkData["sourcePg"] = "srcByLoc";

            trkData.Save();

            NavigationService.Navigate(new Uri("/mapPage.xaml", UriKind.RelativeOrAbsolute));
        }

    }
}